package models

import (
	"shop/shoprpc/shoprpc"

	"gorm.io/gorm"
)

type Shop struct {
	gorm.Model
	Name    string  `gorm:"type:varchar(30);not null;"`
	Price   float64 `gorm:"type:decimal(10,2);not null;"`
	Address string  `gorm:"type:varchar(50);not null;"`
}

func (s *Shop) ShopAdd(db *gorm.DB) error {
	return db.Debug().Create(s).Error
}

func (s *Shop) ShopList(db *gorm.DB) ([]*shoprpc.ShopList, error) {
	var shops []*shoprpc.ShopList
	err2 := db.Debug().Model(&Shop{}).
		Select(
			"shops.id as shop_id",
			"shops.name",
			"shops.price").
		Find(&shops).Error
	return shops, err2
}
